var app = getApp()
Page({

    data: {
        id: '',
        data: '',
        order_id: '',
        addr_id: '',
        openid: '',
        token: ''
    },
    pay: function(e) {
        var type = e.target.dataset.type;
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/order/order_price',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        trade_no: type
                    },
                    success: function(res) {
                        var list = res.data;

                        if (list.code == 1) {
                            wx.navigateTo({
                                url: `../pay-style/pay-style?money=${list.data.price}&order_no=${list.data.trade_no}`,
                            })

                        }
                    }
                })

            },
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log(options)
        this.setData({
            order_id: options.id
        })
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                that.setData({
                    openid: res.data.openid,
                    token: res.data.token,
                })
                wx.request({
                    url: app.url.requestUrl + '/order/orderdetails',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        order_id: options.id
                    },
                    success: function(res) {
                        that.setData({
                            data: res.data.data,
                            money: res.data.data
                        })
                    }
                })
            },
        })



    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this
        wx.getStorage({
            key: 'addr_id',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/order/set_addr',
                    method: 'POST',
                    data: {
                        openid: that.data.openid,
                        token: that.data.token,
                        order_id: parseInt(that.data.order_id),
                        addr_id: parseInt(res.data)
                    },
                    success: function(res) {
                        console.log(res.data)
                        that.setData({
                            data: res.data.data,
                            money: res.data.data
                        })
                    }
                })
            },
        })
    },







})